import 'package:get/get.dart';
import 'package:yysk_app/utils/js_tool.dart';
import 'danation_confirm_widget.dart';

class ToolsModel {
  String time;
  String url;
  String title;

  RxBool  isChoose = false.obs;
  ToolsModel({required this.time,required this.title,required this.url,required this.isChoose});
}

class DanationChooseToolsController extends GetxController {
var   number      = 0.obs;
final bottomEnble = false.obs;
var   dataList    = <ToolsModel>[].obs;
var   chooseList  = <ToolsModel>[];

  @override
  void onInit() {
    super.onInit();
    dataList.value = [
      ToolsModel(time: '2025.09.01 10:00:00', url: '5161',title:'游侠令碎片', isChoose: false.obs),
      ToolsModel(time: '2025.09.01 10:00:00', url: '1234',title:'游侠令碎片', isChoose: false.obs),
      ToolsModel(time: '2025.09.01 10:00:00', url: '1340',title:'游侠令碎片', isChoose: false.obs),

    ]; 
  }

  @override
  void onClose() {
  
    super.onClose();
  }

  void confirmAction()
  {
            
    Get.toNamed(DanationConfirmWidget.path,arguments: {'chooseList': chooseList});
    consoleLog('${chooseList.length.toString()}');
                            // Navigator.of(context).pop();

  }
  void allChooseAction(){
      if(chooseList.isNotEmpty){
         chooseList.clear();
      }
      for ( ToolsModel item in dataList) {
        item.isChoose.value == true;
        chooseList.add(item);
      }

      number.value =  dataList.length;
      bottomEnble.value =  (chooseList.isNotEmpty);
  }
  void updateNumberAction()
  {
    if(chooseList.isNotEmpty){
     chooseList.clear();
    }
    for ( ToolsModel item in dataList) {
      if(item.isChoose.value == true)
      {
      chooseList.add(item);
      }
    }
    number.value =  chooseList.length;
    bottomEnble.value =  (chooseList.isNotEmpty);


  }
   
}
